package edu.ptu.communityplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.ptu.communityplatform.domain.entity.ParkingLot;
import edu.ptu.communityplatform.mapper.ParkingLotMapper;
import edu.ptu.communityplatform.service.IParkingLotService;
import org.springframework.stereotype.Service;

/**
 * @BelongsProject: communityPlatform
 * @BelongsPackage: edu.ptu.communityplatform.service.impl
 * @Author: HYJ
 * @CreateTime: 2025-04-08  19:19
 * @Description: TODO
 * @Version: 1.0
 */
@Service("parkingLotService")
public class ParkingLotServiceImpl extends ServiceImpl<ParkingLotMapper, ParkingLot> implements IParkingLotService {

    @Override
    public IPage<ParkingLot> getParkingLotPage(Integer pageNum, Integer pageSize, Long plotId, String parkingName, Integer type) {
        // 创建分页对象
        Page<ParkingLot> page = new Page<>(pageNum, pageSize);

        // 构建查询条件
        LambdaQueryWrapper<ParkingLot> wrapper = new LambdaQueryWrapper<>();

        // 执行分页查询
        wrapper.eq(ParkingLot::getPlotId, plotId)
                .like(StringUtils.isNotBlank(parkingName),
                        ParkingLot::getParkingName, parkingName)
                .eq(type != null, ParkingLot::getType, type);

        return this.page(page, wrapper);
    }
}
